/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dp1.pucp.Compras.VIsta;

import com.dp1.pucp.Administracion.Vista.*;

import com.dp1.pucp.Administracion.Controlador.BuscarRRHHControlador;
import com.dp1.pucp.Compras.Controlador.MantOrdenCompraControlador;
import com.dp1.pucp.Modelo.Clases.Ordencompra;
import com.dp1.pucp.Util.Validaciones;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author plantilla
 */
public class MantenimientoOrdenCompraGUI extends javax.swing.JPanel {

    /**
     * Creates new form BuscarRRHHGUI
     */
    private JFrame padre;
    private MantOrdenCompraControlador c;

    
    public MantenimientoOrdenCompraGUI() {
        initComponents();
        this.cmbEstado.setEditable(false);
        
           
           dtcFechaInicio.addPropertyChangeListener(new PropertyChangeListener() 
           { @Override public void propertyChange(PropertyChangeEvent evt) { 
               // the docs of JDateChooser says that when the date is modified, a "date" property change is fired 
               if (evt.getPropertyName().equals("date")) { 
                   dtcFechaFin.setMinSelectableDate(dtcFechaInicio.getDate());
               } } } ); 
           
           dtcFechaFin.addPropertyChangeListener(new PropertyChangeListener() 
           { @Override public void propertyChange(PropertyChangeEvent evt) { 
               // the docs of JDateChooser says that when the date is modified, a "date" property change is fired 
               if (evt.getPropertyName().equals("date")) { 
                   dtcFechaInicio.setMaxSelectableDate(dtcFechaFin.getDate()); } } });
    }
      
    public JFrame getPadre(){ return padre; }
    
    public String getCodigo(){ return txtCodigo.getText(); }  
    
    
    
    public Date getFechaIni(){return dtcFechaInicio.getDate();}
    
    public Date getFechaFin(){return dtcFechaFin.getDate();}
        
    public int getEstado(){ return cmbEstado.getSelectedIndex(); }      
        
    public int getFilaSel(){ return tblResultados.getSelectedRow(); }   
    
    public void mostrarAviso(String msn){
        Validaciones.mostrarMensajeAvisoVal(msn);   
    }
    
    public void mostrarError(String msn){
        Validaciones.mostrarMensajeErrorVal(msn);           
    }
    public int solicitarConfirmacion(String msn){
        return Validaciones.solicitarConfirmacionVal(msn);
    }   
    
    public void diferenciarVistas(int i){
        if (i==2){//si es q es para ingresar productos
            this.btnEliminar.setVisible(false);
            this.btnEditar.setVisible(false); //este es el boton ver detalle
            this.btnCrear.setVisible(false);
            
        }
        else if (i==1){
            
            this.btnIngresoMP.setVisible(false);
        }
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        btnLimpiar = new javax.swing.JButton();
        btnBuscar = new javax.swing.JButton();
        btnCrear = new javax.swing.JButton();
        btnEditar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        dtcFechaFin = new com.toedter.calendar.JDateChooser();
        dtcFechaInicio = new com.toedter.calendar.JDateChooser();
        jLabel3 = new javax.swing.JLabel();
        cmbEstado = new javax.swing.JComboBox();
        btnIngresoMP = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblResultados = new javax.swing.JTable();

        setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        setMaximumSize(new java.awt.Dimension(683, 663));
        setMinimumSize(new java.awt.Dimension(683, 663));
        setPreferredSize(new java.awt.Dimension(683, 663));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Buscar", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Ubuntu", 0, 15))); // NOI18N

        jLabel1.setText("Código");

        txtCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCodigoKeyTyped(evt);
            }
        });

        btnLimpiar.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/clear.png"))); // NOI18N
        btnLimpiar.setText("Limpiar");
        btnLimpiar.setBorderPainted(false);
        btnLimpiar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnLimpiar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnLimpiar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        btnBuscar.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/buscar.png"))); // NOI18N
        btnBuscar.setText("Buscar");
        btnBuscar.setBorderPainted(false);
        btnBuscar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnBuscar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnBuscar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        btnCrear.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnCrear.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/nuevo.png"))); // NOI18N
        btnCrear.setText("Nuevo");
        btnCrear.setBorderPainted(false);
        btnCrear.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCrear.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnCrear.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        btnEditar.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/see.png"))); // NOI18N
        btnEditar.setText("Ver Detalle");
        btnEditar.setBorderPainted(false);
        btnEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnEditar.setMaximumSize(new java.awt.Dimension(57, 29));
        btnEditar.setMinimumSize(new java.awt.Dimension(57, 29));
        btnEditar.setPreferredSize(new java.awt.Dimension(57, 29));
        btnEditar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarActionPerformed(evt);
            }
        });

        btnEliminar.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/delete2.png"))); // NOI18N
        btnEliminar.setText("Eliminar");
        btnEliminar.setBorderPainted(false);
        btnEliminar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnEliminar.setMaximumSize(new java.awt.Dimension(57, 29));
        btnEliminar.setMinimumSize(new java.awt.Dimension(57, 29));
        btnEliminar.setPreferredSize(new java.awt.Dimension(57, 29));
        btnEliminar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnEliminar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });

        jLabel5.setText("Fecha Solicitud");

        jLabel2.setText("-");

        dtcFechaFin.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                dtcFechaFinKeyTyped(evt);
            }
        });

        jLabel3.setText("Estado");

        btnIngresoMP.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnIngresoMP.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/edit2.png"))); // NOI18N
        btnIngresoMP.setText("Registrar Ingreso");
        btnIngresoMP.setBorderPainted(false);
        btnIngresoMP.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnIngresoMP.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnIngresoMP.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(78, 78, 78)
                                .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(79, 79, 79)
                                .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(18, 18, 18)
                                .addComponent(dtcFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(btnIngresoMP))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(btnBuscar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnLimpiar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnEditar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(23, 23, 23))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(dtcFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(203, Short.MAX_VALUE))))))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnCrear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(439, 439, 439))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCrear, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel1))
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(dtcFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(dtcFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel3))
                    .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnBuscar)
                    .addComponent(btnLimpiar)
                    .addComponent(btnEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnIngresoMP)))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Resultados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Ubuntu", 0, 15))); // NOI18N

        tblResultados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "CODIGO", "PROVEEDOR", "FECHA SOL.", "FECHA RECP.", "ESTADO", "MONEDA", "MONTO"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblResultados.getTableHeader().setResizingAllowed(false);
        tblResultados.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(tblResultados);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnEditarActionPerformed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnEliminarActionPerformed

    private void dtcFechaFinKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dtcFechaFinKeyTyped
        // TODO add your handling code here:
           
    }//GEN-LAST:event_dtcFechaFinKeyTyped

     //VALIDACIONES
    
    private void txtCodigoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCodigoKeyTyped
        // TODO add your handling code here:
        String car = txtCodigo.getText();
        if(car.length()>=25) evt.consume();        
        Validaciones.soloDigitoTexto(evt);
    }//GEN-LAST:event_txtCodigoKeyTyped

   
 
       
      
       
    public void addNuevoListener(ActionListener ml){ this.btnCrear.addActionListener(ml); }
    
    public void addBuscarListener(ActionListener ml){ this.btnBuscar.addActionListener(ml); }    

    public void addLimpiarListener(ActionListener ml){ this.btnLimpiar.addActionListener(ml); }  

    public void addELiminarListener(ActionListener ml){ this.btnEliminar.addActionListener(ml); }     
    
    public void addEditarListener(ActionListener ml){ this.btnEditar.addActionListener(ml); }          

    public void addIngresoMPListener(ActionListener ml){this.btnIngresoMP.addActionListener(ml);}
 
    
    public ArrayList<Ordencompra> realizarFiltro(ArrayList<Ordencompra> lista) {
       ((DefaultTableModel) this.tblResultados.getModel()).setRowCount(0);
        ArrayList<Ordencompra> listOrden = new ArrayList<>();
        String codigo = txtCodigo.getText();
        Date fechaIni=dtcFechaInicio.getDate();
        Date fechaFin=dtcFechaFin.getDate();

        if (lista.size()==0){ //Esto es si es q en la base de datos no hay ninguna orden guardada
            mostrarAviso("No se ha registrado ninguna Orden de Compra");
        }
        else{
            //veo si es que puso algun codigo, si es que si solo mostrará una orden unica
            if (!(codigo.equals(""))){
                 for (int i = 0; i < lista.size(); i++) {
                    if (codigo.equals(lista.get(i).getCodigo())) {
                    listOrden.add(lista.get(i));
                    }
                }
            }
            else{
                //Para comprobar con las fechas
                if (((fechaIni!=null) & (fechaFin==null))||(fechaIni==null) & (fechaFin!=null)){
                    mostrarError("Debe ingresar un rango de fechas");
                    return null;
                }
                if (this.getEstado() == 0) {
                    if ((fechaIni!=null)&(fechaFin!=null)){
                       for (int i = 0; i < lista.size(); i++) {
                        if (fechaIni.before(lista.get(i).getFechasolicitud()) & (lista.get(i).getFechasolicitud().before(fechaFin))) {
                        listOrden.add(lista.get(i));
                         }
                     }
                    this.llenaGrilla(listOrden);
                    return listOrden;
                    }
                    else {
                    this.llenaGrilla(lista);
                    return lista;
                    }
                }
                
                if ((fechaIni!=null)&(fechaFin!=null)){
                for (int i = 0; i < lista.size(); i++) {
                    if ((this.getEstado()-1 == lista.get(i).getEstado())&fechaIni.before(lista.get(i).getFechasolicitud()) & (lista.get(i).getFechasolicitud().before(fechaFin))) {
                    listOrden.add(lista.get(i));
                    }
                }
                }
                else{
                   for (int i = 0; i < lista.size(); i++) {
                    if (this.getEstado()-1 == lista.get(i).getEstado()) {
                    listOrden.add(lista.get(i));
                    }
                } 
                }
            
            }
        

        this.llenaGrilla(listOrden);
        
        }
        return listOrden;
    }

    // Este realizarFiltro2 es para que solo muestre ordenes en estado registrado o pendiente para ingresar productos
     public ArrayList<Ordencompra> realizarFiltro2(ArrayList<Ordencompra> lista) {
       ((DefaultTableModel) this.tblResultados.getModel()).setRowCount(0);
        ArrayList<Ordencompra> listOrdenAux = new ArrayList<>();
        ArrayList<Ordencompra> listOrden = new ArrayList<>();
        String codigo = txtCodigo.getText();
        Date fechaIni=dtcFechaInicio.getDate();
        Date fechaFin=dtcFechaFin.getDate();

        for (int i = 0; i < lista.size(); i++) {
                    if ((lista.get(i).getEstado()==1) || (lista.get(i).getEstado()==2)) {
                    listOrdenAux.add(lista.get(i));
                    }
        }
        
        if (listOrdenAux.size()==0){ //Esto es si es q no hay ordenen en registrado o pendiente
            mostrarAviso("No se encuentran Ordenes de Compra para ingresar productos");
        }
        else{
            //veo si es que puso algun codigo, si es que si solo mostrará una orden unica
            if (!(codigo.equals(""))){
                 for (int i = 0; i < listOrdenAux.size(); i++) {
                    if (codigo.equals(listOrdenAux.get(i).getCodigo())) {
                    listOrden.add(listOrdenAux.get(i));
                    }
                }
            }
            else{
                //Para comprobar con las fechas
                if (((fechaIni!=null) & (fechaFin==null))||(fechaIni==null) & (fechaFin!=null)){
                    mostrarError("Debe ingresar un rango de fechas");
                    return null;
                }
                if (this.getEstado() == 0) {
                    if ((fechaIni!=null)&(fechaFin!=null)){
                       for (int i = 0; i < listOrdenAux.size(); i++) {
                        if (fechaIni.before(listOrdenAux.get(i).getFechasolicitud()) & (listOrdenAux.get(i).getFechasolicitud().before(fechaFin))) {
                        listOrden.add(listOrdenAux.get(i));
                         }
                     }
                    this.llenaGrilla(listOrden);
                    return listOrden;
                    }
                    else {
                    this.llenaGrilla(listOrdenAux);
                    return listOrdenAux;
                    }
                }
                
                if ((fechaIni!=null)&(fechaFin!=null)){
                for (int i = 0; i < listOrdenAux.size(); i++) {
                    if ((this.getEstado() == listOrdenAux.get(i).getEstado())&fechaIni.before(listOrdenAux.get(i).getFechasolicitud()) & (listOrdenAux.get(i).getFechasolicitud().before(fechaFin))) {
                    listOrden.add(listOrdenAux.get(i));
                    }
                }
                }
                else{
                   for (int i = 0; i < listOrdenAux.size(); i++) {
                    if (this.getEstado() == listOrdenAux.get(i).getEstado()) {
                    listOrden.add(listOrdenAux.get(i));
                    }
                } 
                }
            
            }
        

        this.llenaGrilla(listOrden);
        
        }
        return listOrden;
    }
    
    public void llenaGrilla(ArrayList<Ordencompra> lista){        
        if(lista!=null){ 
            if (lista.size()==0) {
                 mostrarAviso("No se encuentra ninguna Orden de Compra bajo este criterio");}
            else{
            ((DefaultTableModel) this.tblResultados.getModel()).setRowCount(0);
            for (int i = 0; i<lista.size();i++){
                ((DefaultTableModel) tblResultados.getModel()).setRowCount(tblResultados.getRowCount()+1);
                tblResultados.setValueAt(lista.get(i).getCodigo(),i,0);
                tblResultados.setValueAt(lista.get(i).getProveedor().getRazonsocial(),i,1);
                tblResultados.setValueAt(lista.get(i).getFechasolicitud(),i,2);
                if (lista.get(i).getFecharecepcion()!= null){
                 tblResultados.setValueAt(lista.get(i).getFecharecepcion(),i,3);}
                if(lista.get(i).getEstado() ==0){
                    tblResultados.setValueAt("Eliminado",i,4);
                }
                if(lista.get(i).getEstado() ==1){
                    tblResultados.setValueAt("Registrado",i,4);
                } 
                if(lista.get(i).getEstado() ==2){
                    tblResultados.setValueAt("Pendiente",i,4);
                }
                if(lista.get(i).getEstado() ==3){
                    tblResultados.setValueAt("Recibido",i,4);
                }
                tblResultados.setValueAt(lista.get(i).getMoneda().getSimbolo(),i,5);
                tblResultados.setValueAt(lista.get(i).getMontototal(),i,6);
             }
             }
        }
      
            
    }    
              
    public void llenaComboEstado(ArrayList<String> lista){
        if(lista!=null){
            for (String opc : lista){
                cmbEstado.addItem(opc);
            }
        }
    }     
    
    public void LimpiarDatos(){
        txtCodigo.setText("");
        
        dtcFechaInicio.setDate(null);
        dtcFechaFin.setDate(null);
        cmbEstado.setSelectedIndex(0);     
        ((DefaultTableModel) this.tblResultados.getModel()).setRowCount(0);
    }
//    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCrear;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnIngresoMP;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JComboBox cmbEstado;
    private com.toedter.calendar.JDateChooser dtcFechaFin;
    private com.toedter.calendar.JDateChooser dtcFechaInicio;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblResultados;
    private javax.swing.JTextField txtCodigo;
    // End of variables declaration//GEN-END:variables
}
